<?php
/**
 *   Joomdiet - administrator/components/joomdiet.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

/*
 * Define constants for all pages
 */
define( 'COM_JOOMDIET_DIR', 'images'.DS.'joomdiet'.DS );
define( 'COM_JOOMDIET_BASE', JPATH_ROOT.DS.COM_JOOMDIET_DIR );
define( 'COM_JOOMDIET_BASEURL', JURI::root().str_replace( DS, '/', COM_JOOMDIET_DIR ));
define( 'COM_JOOMDIET_UPLOAD_DIR', JPATH_ROOT.DS.'components'.DS.'com_joomdiet'.DS.'uploads' );
define( 'COM_JOOMDIET_THUMBS_DIR', JPATH_ROOT.DS.'components'.DS.'com_joomdiet'.DS.'thumbs' );

// Set helper directory
JHTML::addIncludePath(JPATH_ROOT.DS.'components'.DS.'com_joomdiet'.DS.'helpers'.DS);
JHTML::addIncludePath(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_joomdiet'.DS.'helpers'.DS);
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
//require_once(JPATH_ROOT.DS.'components'.DS.'com_joomdiet'.DS.'helpers'.DS.'helper.php');

// Require the base controller
require_once JPATH_COMPONENT.DS.'controller.php';

// Require the base controller
require_once JPATH_COMPONENT.DS.'helpers'.DS.'helper.php';

// Initialize the dedicated controller
if ($controller = JRequest::getWord('controller')) {
    // determine path
    $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
    if (file_exists($path)) {
        require_once $path;
    } else $controller = '';
}

$classname = 'JoomdietController'.$controller;
$controller = new $classname();

// Perform the Request task
$controller->execute( JRequest::getVar('task'));
$controller->redirect();
?>
